* Please ensure that you have enabled the YouTube Data API for your project.
*/
$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes('https://www.googleapis.com/auth/youtube');
//$redirectUri = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],FILTER_SANITIZE_URL);
$redirectUri = "{$global['webSiteRootURL']}objects/youtubeUpload.json.php";
$redirect = "{$global['webSiteRootURL']}mvideos";
$client->setRedirectUri($redirectUri);
// Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
// Check if an auth token exists for the required scopes
$tokenSessionKey = 'token-' . $client->prepareScopes();
if (isset($_GET['code'])) {
if (strval($_SESSION['state']) !== strval($_GET['state'])) {
die('The session state did not match.');
}
$client->authenticate($_GET['code']);
$_SESSION[$tokenSessionKey] = $client->getAccessToken();
header('Location: ' . $redirect);
}
if (!is_array($_POST['id'])) {
$_POST['id'] = array($_POST['id']);
}
foreach ($_POST['id'] as $value) {
$v = new Video("", "", $value);
if (!$v->userCanManageVideo()) {
$obj->msg = __("You can not Manage This Video");
die(json_encode($obj));
}
if (isset($_SESSION[$tokenSessionKey])) {
$client->setAccessToken($_SESSION[$tokenSessionKey]);
}
-// Check to ensure that the access token was successfully acquired.
+ // Check to ensure that the access token was successfully acquired.
if ($client->getAccessToken()) {
try {
// REPLACE this value with the path to the file you are uploading.
$videoPath = $v->getExistingVideoFile();
// Create a snippet with title, description, tags and category ID
// Create an asset resource and set its snippet metadata and type.
// This example sets the video's title, description, keyword tags, and
// video category.
$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle($v->getTitle());
$snippet->setDescription($v->getDescription());
$snippet->setTags(array("AVideo", $config->getWebSiteTitle()));
// Numeric video category. See
// https://developers.google.com/youtube/v3/docs/videoCategories/list
// $snippet->setCategoryId("22");
// Set the video's status to "public". Valid statuses are "public",
// "private" and "unlisted".
$status = new Google_Service_YouTube_VideoStatus();
$status->privacyStatus = "public";
// Associate the snippet and status objects with a new video resource.
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
// Specify the size of each chunk of data, in bytes. Set a higher value for
// reliable connection as fewer chunks lead to faster uploads. Set a lower
// value for better recovery on less reliable connections.
$chunkSizeBytes = 1 * 1024 * 1024;
// Setting the defer flag to true tells the client to return a request which can be called
// with ->execute(); instead of making the API call immediately.
$client->setDefer(true);
// Create a request for the API's videos.insert method to create and upload the video.
$insertRequest = $youtube->videos->insert("status,snippet", $video);
// Create a MediaFileUpload object for resumable uploads.
$media = new Google_Http_MediaFileUpload(
- $client, $insertRequest, 'video/*', null, true, $chunkSizeBytes
+ $client,
+ $insertRequest,
+ 'video/*',
+ null,
+ true,
+ $chunkSizeBytes
);
$media->setFileSize(filesize($videoPath));
// Read the media file and upload it chunk by chunk.
$status = false;
$handle = fopen($videoPath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
// If you want to make other calls after the file upload, set setDefer back to false
$client->setDefer(false);
$obj->success = true;
$obj->title = $status['snippet']['title'];
$obj->id = $status['id'];
$obj->status = $status;
$obj->msg = sprintf(__("Your video %s was uploaded to your YouTube Account
", true), $obj->id, $obj->title);
$v->setYoutubeId($obj->id);
$v->save();
} catch (Google_Service_Exception $e) {
$obj->msg = sprintf(__("A service error occurred: %s"), $e->getMessage());
} catch (Google_Exception $e) {
$obj->msg = sprintf(__("An client error occurred: %s"), $e->getMessage());
}
$_SESSION[$tokenSessionKey] = $client->getAccessToken();
} elseif ($OAUTH2_CLIENT_ID == 'REPLACE_ME') {
$obj->msg = "Client Credentials Required
You need to set \$OAUTH2_CLIENT_ID and
\$OAUTH2_CLIENT_ID before proceeding.
";
} else {
// If the user hasn't authorized the app, initiate the OAuth flow
$state = mt_rand();
$client->setState($state);
$_SESSION['state'] = $state;
$authUrl = $client->createAuthUrl();
$obj->msg = "
Authorization Required
You need to authorize access before proceeding.
";
}
}
echo json_encode($obj);
diff --git a/plugin/ReportVideo/ReportVideo.php b/plugin/ReportVideo/ReportVideo.php
index 551d9f48c..002f2ae8a 100644
--- a/plugin/ReportVideo/ReportVideo.php
+++ b/plugin/ReportVideo/ReportVideo.php
@@ -1,290 +1,305 @@
emailLogo = "";
return $obj;
}
- public function getPluginVersion() {
+ public function getPluginVersion()
+ {
return "2.2";
}
- public function updateScript() {
+ public function updateScript()
+ {
global $global;
//update version 2.0
if (AVideoPlugin::compareVersion($this->getName(), "2.0") < 0) {
$sqls = file_get_contents($global['systemRootPath'] . 'plugin/ReportVideo/install/updateV2.0.sql');
$sqlParts = explode(";", $sqls);
foreach ($sqlParts as $value) {
sqlDal::writeSql(trim($value));
}
}
//update version 2.1
if (AVideoPlugin::compareVersion($this->getName(), "2.1") < 0) {
$sqls = file_get_contents($global['systemRootPath'] . 'plugin/ReportVideo/install/updateV2.1.sql');
$sqlParts = explode(";", $sqls);
foreach ($sqlParts as $value) {
sqlDal::writeSql(trim($value));
}
}
return true;
}
- public function getWatchActionButton($videos_id) {
+ public function getWatchActionButton($videos_id)
+ {
global $global, $video;
if (!isVideo()) {
return '';
}
if (empty($video['id']) && empty($videos_id)) {
return '';
}
if (empty($video['id'])) {
$video['id'] = intval($videos_id);
}
include $global['systemRootPath'] . 'plugin/ReportVideo/actionButton.php';
if (isVideo() && !empty($video['users_id'])) {
$users_id = $video['users_id'];
echo self::actionButtonBlockUser($users_id);
}
}
- function send($email, $subject, $body) {
+ public function send($email, $subject, $body)
+ {
if (empty($email)) {
return false;
}
global $global, $config;
- require_once $global['systemRootPath'] . 'objects/include_phpmailer.php';
-
//Create a new PHPMailer instance
$mail = new \PHPMailer\PHPMailer\PHPMailer;
setSiteSendMessage($mail);
//Set who the message is to be sent from
$mail->setFrom($config->getContactEmail(), $config->getWebSiteTitle());
//Set who the message is to be sent to
$mail->addAddress($email);
//$mail->addAddress($config->getContactEmail());
//Set the subject line
$mail->Subject = $subject;
$mail->msgHTML($body);
//send the message, check for errors
if ($mail->send()) {
_error_log("Notification email sent [{$subject}]");
return true;
} else {
_error_log("Notification email FAIL [{$subject}] - " . $mail->ErrorInfo);
return false;
}
}
- private function replaceText($users_id, $videos_id, $text) {
-
+ private function replaceText($users_id, $videos_id, $text)
+ {
$user = new User($users_id);
$userName = $user->getNameIdentification();
$video = new Video("", "", $videos_id);
$videoName = $video->getTitle();
$videoLink = Video::getPermaLink($videos_id);
$words = array($userName, $videoName, $videoLink);
$replace = array('{user}', '{videoName}', '{videoLink}');
return str_replace($replace, $words, $text);
}
- private function getTemplateText($videos_id, $message) {
+ private function getTemplateText($videos_id, $message)
+ {
global $global, $config;
$obj = $this->getDataObject();
$text = file_get_contents("{$global['systemRootPath']}plugin/ReportVideo/template.html");
$video = new Video("", "", $videos_id);
$videoName = $video->getTitle();
$images = Video::getImageFromFilename($video->getFilename());
$videoThumbs = "
";
$videoLink = Video::getPermaLink($videos_id);
$logo = "
";
$siteTitle = $config->getWebSiteTitle();
$footer = "";
$words = array($logo, $videoName, $videoThumbs, $videoLink, $siteTitle, $footer, $message);
$replace = array('{logo}', '{videoName}', '{videoThumbs}', '{videoLink}', '{siteTitle}', '{footer}', '{message}');
return str_replace($replace, $words, $text);
}
- function report($users_id, $videos_id) {
+ public function report($users_id, $videos_id)
+ {
global $global, $config;
// check if this user already report this video
$report = VideosReported::getFromDbUserAndVideo($users_id, $videos_id);
$resp = new stdClass();
$resp->error = true;
$resp->msg = "Report not made";
if (empty($report)) {
//save it on the database
$reportObj = new VideosReported(0);
$reportObj->setUsers_id($users_id);
$reportObj->setVideos_id($videos_id);
if ($reportObj->save()) {
$body = $this->getTemplateText($videos_id, $this->replaceText($users_id, $videos_id, "The {videoName} video was reported as inapropriate from {user} "));
$subject = $this->replaceText($users_id, $videos_id, "The {videoName} video was reported as inapropriate");
// notify video owner from user id
$user = new User($users_id);
$email = $user->getEmail();
$videoOwnerSent = $this->send($email, $subject, $body);
// notify site owner from configuratios email
$siteOwnerEmail = $config->getContactEmail();
$siteOwnerSent = $this->send($siteOwnerEmail, $subject, $body);
if (!$videoOwnerSent && !$siteOwnerSent) {
$resp->msg = __("We could not notify anyone ({$email}, {$siteOwnerEmail}), but we marked it as a inapropriated");
- } else if (!$videoOwnerSent) {
+ } elseif (!$videoOwnerSent) {
$resp->msg = __("We could not notify the video owner {$email}, but we marked it as a inapropriated");
- } else if (!$siteOwnerSent) {
+ } elseif (!$siteOwnerSent) {
$resp->msg = __("We could not notify the video owner {$siteOwnerEmail}, but we marked it as a inapropriated");
} else {
$resp->error = false;
$resp->msg = __("This video was reported to our team, we will review it soon");
}
} else {
$resp->msg = __("Error on report this video");
}
} else {
$resp->msg = __("You already report this video");
}
if ($resp->error === true) {
_error_log("Report Video: " . $resp->msg);
}
return $resp;
}
- function block($users_id, $reported_users_id) {
+ public function block($users_id, $reported_users_id)
+ {
global $global, $config;
// check if this user already report this video
$report = VideosReported::getFromDbUserAndReportedUser($users_id, $reported_users_id);
$resp = new stdClass();
$resp->error = true;
$resp->msg = "Block not made";
if (empty($report)) {
//save it on the database
$reportObj = new VideosReported(0);
$reportObj->setUsers_id($users_id);
$reportObj->setReported_users_id($reported_users_id);
if ($reportObj->save()) {
$resp->msg = "";
$resp->error = false;
} else {
$resp->msg = __("Error on block this user");
}
} else {
$resp->msg = __("User Already blocked");
}
if ($resp->error === true) {
_error_log("Block User: " . $resp->msg);
}
return $resp;
}
- function unBlock($users_id, $reported_users_id) {
+ public function unBlock($users_id, $reported_users_id)
+ {
global $global, $config;
// check if this user already report this video
$report = VideosReported::getFromDbUserAndReportedUser($users_id, $reported_users_id);
$resp = new stdClass();
$resp->error = true;
$resp->msg = "Block not made";
if (!empty($report)) {
//save it on the database
$reportObj = new VideosReported($report['id']);
if ($reportObj->delete()) {
$resp->msg = "";
$resp->error = false;
} else {
$resp->msg = __("Error on unblock this user");
}
} else {
$resp->msg = __("User Already unblocked");
}
if ($resp->error === true) {
_error_log("Block user: " . $resp->msg);
}
return $resp;
}
- static function isBlocked($reported_users_id, $users_id = 0) {
+ public static function isBlocked($reported_users_id, $users_id = 0)
+ {
global $global, $config;
if (empty($users_id)) {
$users_id = User::getId();
}
$users_id = intval($users_id);
// check if this user already report this video
$reportedUsersId = VideosReported::getAllReportedUsersIdFromUser($users_id);
return in_array($reported_users_id, $reportedUsersId);
}
- static function getAllReportedUsersIdFromUser($users_id=0) {
+ public static function getAllReportedUsersIdFromUser($users_id=0)
+ {
if (empty($users_id)) {
$users_id = User::getId();
}
$users_id = intval($users_id);
return VideosReported::getAllReportedUsersIdFromUser($users_id);
}
- static function buttonBlockUser($users_id) {
+ public static function buttonBlockUser($users_id)
+ {
if ($users_id == User::getId()) {
return '';
}
global $global, $config;
$variable = ob_get_clean();
ob_start();
include $global['systemRootPath'] . 'plugin/ReportVideo/buttonBlockUser.php';
$button = ob_get_clean();
ob_start();
echo $variable;
return $button;
}
- static function actionButtonBlockUser($users_id) {
+ public static function actionButtonBlockUser($users_id)
+ {
if ($users_id == User::getId()) {
return '';
}
global $global, $config;
$variable = ob_get_clean();
ob_start();
include $global['systemRootPath'] . 'plugin/ReportVideo/actionButtonBlockUser.php';
$button = ob_get_clean();
ob_start();
echo $variable;
return $button;
}
-
}
diff --git a/plugin/YPTWallet/YPTWallet.php b/plugin/YPTWallet/YPTWallet.php
index 294f2c9e0..6809e8869 100644
--- a/plugin/YPTWallet/YPTWallet.php
+++ b/plugin/YPTWallet/YPTWallet.php
@@ -1,610 +1,647 @@
decimalPrecision = 2;
$obj->wallet_button_title = "My Wallet";
$obj->add_funds_text = "
Adding money instantly from credit/debit card
Add funds on your Account Balance, to support our videos";
$obj->add_funds_success_success = "Thank you,
Your funds has been added";
$obj->add_funds_success_cancel = "Ops,
You have cancel it";
$obj->add_funds_success_fail = "Sorry,
Your funds request has been fail";
$obj->transfer_funds_text = "Transfer money for other users
Transfer funds from your account to another user account";
$obj->transfer_funds_success_success = "Thank you,
Your funds has been transfered";
$obj->transfer_funds_success_fail = "Sorry,
Your funds transfer request has been fail";
$obj->withdraw_funds_text = "Withdraw money from your
Transfer funds from your account to your credit card or bank account";
$obj->withdraw_funds_success_success = "Thank you,
Your request was submited";
$obj->withdraw_funds_success_fail = "Sorry,
Your funds withdraw request has been fail";
$obj->virtual_currency = "HEART"; // we will show this currency on the wallet but we will not make transactions on the payment gateway with it
$obj->virtual_currency_symbol = "❤"; // we will show this currency on the wallet but we will not make transactions on the payment gateway with it
$obj->virtual_currency_exchange_rate = "2"; // means 1 real currency will be 2 virtual currencies
$obj->virtual_currency_decimalPrecision = 2.5; // the value 2.5 on it means if you purchase 2 real currency it will worth 5 virtual currencies
$obj->virtual_currency_enable = false;
$obj->currency = "USD";
$obj->currency_symbol = "$";
$obj->addFundsOptions = "[5,10,20,50]";
$obj->showWalletOnlyToAdmin = false;
$obj->CryptoWalletName = "Bitcoin Wallet Address";
$obj->enableAutomaticAddFundsPage = true;
// add funds
$obj->enableManualAddFundsPage = false;
$obj->manualAddFundsMenuTitle = "Add Funds/Deposit";
$obj->manualAddFundsPageButton = "Notify Deposit Made";
$obj->manualAddFundsNotifyEmail = "yourEmail@yourDomain.com";
$obj->manualAddFundsTransferFromUserId = 1;
// sell funds
$obj->enableManualWithdrawFundsPage = true;
$obj->withdrawFundsOptions = "[5,10,20,50,100,1000]";
$obj->manualWithdrawFundsMenuTitle = "Withdraw Funds";
$obj->manualWithdrawFundsPageButton = "Request Withdraw";
$obj->manualWithdrawFundsNotifyEmail = "yourEmail@yourDomain.com";
$obj->manualWithdrawFundsminimum = 1;
$obj->manualWithdrawFundsmaximum = 100;
$obj->manualWithdrawFundsTransferToUserId = 1;
$plugins = self::getAvailablePlugins();
foreach ($plugins as $value) {
$eval = "\$obj->enablePlugin_{$value} = false;";
eval($eval);
$dataObj = self::getPluginDataObject($value);
$obj = (object) array_merge((array) $obj, (array) $dataObj);
}
return $obj;
}
- public function getBalance($users_id) {
+ public function getBalance($users_id)
+ {
$wallet = self::getWallet($users_id);
return $wallet->getBalance();
}
- public function getBalanceText($users_id) {
+ public function getBalanceText($users_id)
+ {
$balance = $this->getBalanceFormated($users_id);
return self::formatCurrency($balance);
}
- public function getBalanceFormated($users_id) {
+ public function getBalanceFormated($users_id)
+ {
$balance = $this->getBalance($users_id);
$obj = $this->getDataObject();
return number_format($balance, $obj->decimalPrecision);
}
- static function formatCurrency($value, $addHTML=false, $doNotUseVirtualCurrency = false) {
+ public static function formatCurrency($value, $addHTML=false, $doNotUseVirtualCurrency = false)
+ {
$value = floatval($value);
$obj = AVideoPlugin::getObjectData('YPTWallet');
$currency_symbol = $obj->currency_symbol;
$decimalPrecision = $obj->decimalPrecision;
$currency = $obj->currency;
if (empty($doNotUseVirtualCurrency) && $obj->virtual_currency_enable) {
$currency_symbol = $obj->virtual_currency_symbol;
$decimalPrecision = $obj->virtual_currency_decimalPrecision;
$currency = $obj->virtual_currency;
}
$value = number_format($value, $decimalPrecision);
- if($addHTML){
+ if ($addHTML) {
return "{$currency_symbol} {$value} {$currency}";
- }else{
+ } else {
return "{$currency_symbol} {$value} {$currency}";
}
}
- static function getStep($doNotUseVirtualCurrency = false) {
+ public static function getStep($doNotUseVirtualCurrency = false)
+ {
$obj = AVideoPlugin::getObjectData('YPTWallet');
$decimalPrecision = $obj->decimalPrecision;
if ($obj->virtual_currency_enable) {
$decimalPrecision = $obj->virtual_currency_decimalPrecision;
}
- if(empty($decimalPrecision)){
+ if (empty($decimalPrecision)) {
return 1;
}
return "0.".str_repeat("0", $decimalPrecision-1)."1";
}
- static function formatFloat($value) {
+ public static function formatFloat($value)
+ {
$value = floatval($value);
$obj = AVideoPlugin::getObjectData('YPTWallet');
return number_format($value, $obj->decimalPrecision);
}
- static function getWallet($users_id) {
+ public static function getWallet($users_id)
+ {
$wallet = new Wallet(0);
$wallet->setUsers_id($users_id);
return $wallet;
}
- public function getOrCreateWallet($users_id) {
+ public function getOrCreateWallet($users_id)
+ {
$wallet = new Wallet(0);
$wallet->setUsers_id($users_id);
if (empty($wallet->getId())) {
$wallet_id = $wallet->save();
$wallet = new Wallet($wallet_id);
}
return $wallet;
}
- function getAllUsers($activeOnly = true) {
+ public function getAllUsers($activeOnly = true)
+ {
global $global;
$sql = "SELECT w.*, u.*, u.id as user_id, IFNULL(balance, 0) as balance FROM users u "
. " LEFT JOIN wallet w ON u.id = w.users_id WHERE 1=1 ";
if ($activeOnly) {
$sql .= " AND status = 'a' ";
}
$sql .= BootGrid::getSqlFromPost(array('name', 'email', 'user'));
$res = $global['mysqli']->query($sql);
$user = array();
if ($res) {
while ($row = $res->fetch_assoc()) {
$row['name'] = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/u', '', $row['name']);
$row['identification'] = User::getNameIdentificationById($row['user_id']);
$row['identification'] = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/u', '', $row['identification']);
unset($row['about']);
$row['background'] = User::getBackground($row['user_id']);
$row['photo'] = User::getPhoto($row['user_id']);
$row['crypto_wallet_address'] = "";
$user[] = $row;
}
//$user = $res->fetch_all(MYSQLI_ASSOC);
} else {
$user = false;
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return $user;
}
- static function getTotalBalance() {
+ public static function getTotalBalance()
+ {
global $global;
$sql = "SELECT sum(balance) as total FROM wallet ";
$res = $global['mysqli']->query($sql);
$user = array();
if ($res) {
if ($row = $res->fetch_assoc()) {
return $row['total'];
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
return 0;
}
- static function getTotalBalanceText() {
+ public static function getTotalBalanceText()
+ {
$value = self::getTotalBalance();
return self::formatCurrency($value);
}
- public function getHistory($user_id) {
+ public function getHistory($user_id)
+ {
$wallet = self::getWallet($user_id);
$log = new WalletLog(0);
$rows = $log->getAllFromWallet($wallet->getId());
return $rows;
}
- static function exchange($value){
+ public static function exchange($value)
+ {
$obj = AVideoPlugin::getObjectData('YPTWallet');
$value = floatval($value);
$virtual_currency_exchange_rate = floatval($obj->virtual_currency_exchange_rate);
if (!empty($virtual_currency_exchange_rate)) {
$value *= $virtual_currency_exchange_rate;
}
return $value;
}
/**
*
* @param type $users_id
* @param type $value
* @param type $description
* @param type $json_data
* @param type $mainWallet_user_id A user ID where the money comes from and where the money goes for
*/
- public function addBalance($users_id, $value, $description = "", $json_data = "{}", $mainWallet_user_id = 0, $noNotExchangeValue = false) {
+ public function addBalance($users_id, $value, $description = "", $json_data = "{}", $mainWallet_user_id = 0, $noNotExchangeValue = false)
+ {
global $global;
$obj = $this->getDataObject();
- if(empty($noNotExchangeValue) && !empty($obj->virtual_currency_enable)){
+ if (empty($noNotExchangeValue) && !empty($obj->virtual_currency_enable)) {
$originalValue = $value;
$value = self::exchange($value);
$originalValueFormated = self::formatCurrency($originalValue, false, true);
$valueFormated = self::formatCurrency($value);
$description .= " Rate Exchanged {$originalValueFormated} => {$valueFormated} ";
}
$wallet = $this->getOrCreateWallet($users_id);
$balance = $wallet->getBalance();
_error_log("YPTWallet::addBalance BEFORE (user_id={$users_id}) (balance={$balance})");
$balance += $value;
$wallet->setBalance($balance);
$wallet_id = $wallet->save();
WalletLog::addLog($wallet_id, $value, $description, $json_data, "success", "addBalance");
if (!empty($mainWallet_user_id)) {
$wallet = $this->getOrCreateWallet($mainWallet_user_id);
$balance = $wallet->getBalance();
$balance += ($value * -1);
$wallet->setBalance($balance);
$wallet_id = $wallet->save();
$user = new User($users_id);
WalletLog::addLog($wallet_id, ($value * -1), " From user ($users_id) " . $user->getUser() . " - " . $description, $json_data, "success", "addBalance to main wallet");
}
$wallet = $this->getOrCreateWallet($users_id);
$balance = $wallet->getBalance();
_error_log("YPTWallet::addBalance AFTER (user_id={$users_id}) (balance={$balance})");
//_error_log("YPTWallet::addBalance $wallet_id, $value, $description, $json_data");
}
- public function saveBalance($users_id, $value) {
+ public function saveBalance($users_id, $value)
+ {
if (!User::isAdmin()) {
return false;
}
$wallet = self::getWallet($users_id);
$balance = $wallet->getBalance();
$wallet->setBalance($value);
$wallet_id = $wallet->save();
$description = "Admin set your balance, from {$balance} to {$value}";
WalletLog::addLog($wallet_id, $value, $description, "{}", "success", "saveBalance");
}
- static function transferBalanceToSiteOwner($users_id_from, $value, $description = "", $forceTransfer = false) {
+ public static function transferBalanceToSiteOwner($users_id_from, $value, $description = "", $forceTransfer = false)
+ {
$obj = AVideoPlugin::getObjectData('YPTWallet');
if (empty($obj->manualWithdrawFundsTransferToUserId)) {
_error_log("YPTWallet::transferBalanceToSiteOwner site owner is not defined in the plugin, define it on the option manualWithdrawFundsTransferToUserId", AVideoLog::$ERROR);
}
return self::transferBalance($users_id_from, $obj->manualWithdrawFundsTransferToUserId, $value, $description, $forceTransfer);
}
- static function transferBalanceFromSiteOwner($users_id_from, $value, $description = "", $forceTransfer = false) {
+ public static function transferBalanceFromSiteOwner($users_id_from, $value, $description = "", $forceTransfer = false)
+ {
$obj = AVideoPlugin::getObjectData('YPTWallet');
return self::transferBalance($obj->manualWithdrawFundsTransferToUserId, $users_id_from, $value, $description, $forceTransfer);
}
- static function transferBalanceFromMeToSiteOwner($value) {
+ public static function transferBalanceFromMeToSiteOwner($value)
+ {
if (!User::isLogged()) {
return false;
}
return self::transferBalanceToSiteOwner(User::getId(), $value);
}
- static function transferBalanceFromOwnerToMe($value) {
+ public static function transferBalanceFromOwnerToMe($value)
+ {
if (!User::isLogged()) {
return false;
}
return self::transferBalanceFromSiteOwner(User::getId(), $value);
}
- static function transferBalance($users_id_from, $users_id_to, $value, $forceDescription = "", $forceTransfer = false) {
+ public static function transferBalance($users_id_from, $users_id_to, $value, $forceDescription = "", $forceTransfer = false)
+ {
global $global;
_error_log("transferBalance: $users_id_from, $users_id_to, $value, $forceDescription, $forceTransfer");
if (!User::isAdmin()) {
if ($users_id_from != User::getId() && !$forceTransfer) {
_error_log("transferBalance: you are not admin, $users_id_from,$users_id_to, $value");
return false;
}
}
if (!User::idExists($users_id_from) || !User::idExists($users_id_to)) {
_error_log("transferBalance: user does not exists, $users_id_from,$users_id_to, $value");
return false;
}
$value = floatval($value);
if ($value <= 0) {
return false;
}
$wallet = self::getWallet($users_id_from);
$balance = $wallet->getBalance();
$newBalance = $balance - $value;
if ($newBalance < 0) {
_error_log("transferBalance: you dont have balance, $users_id_from,$users_id_to, $value (Balance: {$balance}) (New Balance: {$newBalance})");
return false;
}
$identificationFrom = User::getNameIdentificationById($users_id_from);
$identificationTo = User::getNameIdentificationById($users_id_to);
$wallet->setBalance($newBalance);
$wallet_id = $wallet->save();
$description = "Transfer Balance {$value} from YOU to user {$identificationTo}";
if (!empty($forceDescription)) {
$description = $forceDescription;
}
WalletLog::addLog($wallet_id, "-" . $value, $description, "{}", "success", "transferBalance to");
$wallet = self::getWallet($users_id_to);
$balance = $wallet->getBalance();
$newBalance = $balance + $value;
$wallet->setBalance($newBalance);
$wallet_id = $wallet->save();
$description = "Transfer Balance {$value} from user {$identificationFrom} to YOU";
if (!empty($forceDescription)) {
$description = $forceDescription;
}
ObjectYPT::clearSessionCache();
WalletLog::addLog($wallet_id, $value, $description, "{}", "success", "transferBalance from");
return true;
}
- public function getHTMLMenuRight() {
+ public function getHTMLMenuRight()
+ {
global $global;
if (!User::isLogged()) {
return "";
}
$obj = $this->getDataObject();
if ($obj->showWalletOnlyToAdmin && !User::isAdmin()) {
return "";
}
include $global['systemRootPath'] . 'plugin/YPTWallet/view/menuRight.php';
}
- static function getAvailablePayments() {
+ public static function getAvailablePayments()
+ {
global $global;
if (!User::isLogged()) {
$redirectUri = getSelfURI();
if (!empty($redirectUri)) {
$redirectUri = "&redirectUri=" . urlencode($redirectUri);
}
echo '';
return false;
}
$dir = self::getPluginDir();
$plugins = self::getEnabledPlugins();
foreach ($plugins as $value) {
$subdir = $dir . DIRECTORY_SEPARATOR . $value . DIRECTORY_SEPARATOR;
$file = $subdir . "{$value}.php";
if (is_dir($subdir) && file_exists($file)) {
require_once $file;
$eval = "\$obj = new {$value}();\$obj->getAprovalButton();";
eval($eval);
}
}
return true;
}
- static function getAvailableRecurrentPayments() {
+ public static function getAvailableRecurrentPayments()
+ {
global $global;
if (!User::isLogged()) {
$redirectUri = getSelfURI();
if (!empty($redirectUri)) {
$redirectUri = "&redirectUri=" . urlencode($redirectUri);
}
echo '';
return false;
}
$dir = self::getPluginDir();
$plugins = self::getEnabledPlugins();
foreach ($plugins as $value) {
$subdir = $dir . DIRECTORY_SEPARATOR . $value . DIRECTORY_SEPARATOR;
$file = $subdir . "{$value}.php";
if (is_dir($subdir) && file_exists($file)) {
require_once $file;
$eval = "\$obj = new {$value}();\$obj->getRecurrentAprovalButton();";
eval($eval);
}
}
}
- static function getAvailablePlugins() {
+ public static function getAvailablePlugins()
+ {
$dir = self::getPluginDir();
$dirs = scandir($dir);
$plugins = array();
foreach ($dirs as $key => $value) {
if (!in_array($value, array(".", ".."))) {
$subdir = $dir . DIRECTORY_SEPARATOR . $value . DIRECTORY_SEPARATOR;
$file = $subdir . "{$value}.php";
if (is_dir($subdir) && file_exists($file)) {
$plugins[] = $value;
}
}
}
return $plugins;
}
- static function getEnabledPlugins() {
+ public static function getEnabledPlugins()
+ {
global $global;
$plugins = self::getAvailablePlugins();
$wallet = new YPTWallet();
$obj = $wallet->getDataObject();
foreach ($plugins as $key => $value) {
$eval = "\$val = \$obj->enablePlugin_{$value};";
eval($eval);
if (empty($val)) {
unset($plugins[$key]);
}
}
return $plugins;
}
- static function getPluginDataObject($pluginName) {
+ public static function getPluginDataObject($pluginName)
+ {
$dir = self::getPluginDir();
$file = $dir . "/{$pluginName}/{$pluginName}.php";
if (file_exists($file)) {
require_once $file;
$eval = "\$obj = new {$pluginName}();";
eval($eval);
return $obj->getEmptyDataObject();
}
return array();
}
- static function getPluginDir() {
+ public static function getPluginDir()
+ {
global $global;
$dir = $global['systemRootPath'] . "plugin/YPTWallet/plugins";
return $dir;
}
- function sendEmails($emailsArray, $subject, $message) {
+ public function sendEmails($emailsArray, $subject, $message)
+ {
global $global, $config;
$siteTitle = $config->getWebSiteTitle();
$footer = $config->getWebSiteTitle();
$body = $this->replaceTemplateText($siteTitle, $footer, $message);
return $this->send($emailsArray, $subject, $body);
}
- private function replaceTemplateText($siteTitle, $footer, $message) {
+ private function replaceTemplateText($siteTitle, $footer, $message)
+ {
global $global, $config;
$text = file_get_contents("{$global['systemRootPath']}plugin/YPTWallet/template.html");
$words = array($siteTitle, $footer, $message);
$replace = array('{siteTitle}', '{footer}', '{message}');
return str_replace($replace, $words, $text);
}
- private function send($emailsArray, $subject, $body) {
+ private function send($emailsArray, $subject, $body)
+ {
if (empty($emailsArray)) {
return false;
}
$emailsArray = array_unique($emailsArray);
global $global, $config;
- require_once $global['systemRootPath'] . 'objects/include_phpmailer.php';
-
//Create a new PHPMailer instance
$mail = new \PHPMailer\PHPMailer\PHPMailer;
setSiteSendMessage($mail);
//Set who the message is to be sent from
$mail->setFrom($config->getContactEmail(), $config->getWebSiteTitle());
//Set who the message is to be sent to
foreach ($emailsArray as $value) {
if (empty($value)) {
continue;
}
$mail->addBCC($value);
}
//Set the subject line
$mail->Subject = $subject;
$mail->msgHTML($body);
//send the message, check for errors
if (!$mail->send()) {
_error_log("Wallet email FAIL [{$subject}] {$mail->ErrorInfo}");
return false;
} else {
_error_log("Wallet email sent [{$subject}]");
return true;
}
}
/**
*
* @param type $wallet_log_id
* @param type $new_status
* return true if balance is enought
*/
- function processStatus($wallet_log_id, $new_status) {
+ public function processStatus($wallet_log_id, $new_status)
+ {
$obj = $this->getDataObject();
$walletLog = new WalletLog($wallet_log_id);
$wallet = new Wallet($walletLog->getWallet_id());
$oldStatus = $walletLog->getStatus();
if ($walletLog->getType() == self::MANUAL_WITHDRAW) {
if ($new_status != $oldStatus) {
if ($oldStatus == "success" || $oldStatus == "pending") {
if ($new_status == "canceled") {
// return the value
return self::transferBalance($obj->manualWithdrawFundsTransferToUserId, $wallet->getUsers_id(), $walletLog->getValue());
} else {
// keep the value
return true;
}
}
// get the value again
if ($oldStatus == "canceled") {
return self::transferBalance($wallet->getUsers_id(), $obj->manualWithdrawFundsTransferToUserId, $walletLog->getValue());
}
}
- } else if ($walletLog->getType() == self::MANUAL_ADD) {
+ } elseif ($walletLog->getType() == self::MANUAL_ADD) {
if ($oldStatus == "pending") {
if ($new_status == "canceled") {
// do nothing
return true;
- } else if ($new_status == "success") {
+ } elseif ($new_status == "success") {
// transfer the value
return self::transferBalance($obj->manualAddFundsTransferFromUserId, $wallet->getUsers_id(), $walletLog->getValue());
}
- } else if ($oldStatus == "success") {
+ } elseif ($oldStatus == "success") {
//get the money back
return self::transferBalance($wallet->getUsers_id(), $obj->manualAddFundsTransferFromUserId, $walletLog->getValue());
- } else if ($oldStatus == "canceled") {
+ } elseif ($oldStatus == "canceled") {
if ($new_status == "pending") {
// do nothing
return true;
- } else if ($new_status == "success") {
+ } elseif ($new_status == "success") {
// transfer the value
return self::transferBalance($obj->manualAddFundsTransferFromUserId, $wallet->getUsers_id(), $walletLog->getValue());
}
}
}
return true;
}
- static function getUserBalance($users_id=0){
- if(empty($users_id)){
+ public static function getUserBalance($users_id=0)
+ {
+ if (empty($users_id)) {
$users_id = User::getId();
}
- if(empty($users_id)){
+ if (empty($users_id)) {
return 0;
}
$wallet = self::getWallet($users_id);
return $wallet->getBalance();
}
- public function getFooterCode() {
+ public function getFooterCode()
+ {
global $global;
$obj = $this->getDataObject();
$js = "";
$js .= "";
return $js;
}
-
}